package com.fiveGroup.controller;

import cn.hutool.core.util.StrUtil;
import com.fiveGroup.util.OSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * ClassName: FileConller
 * Package:
 * Description
 * 测试文件
 * 可以删除
 *
 * @Author wen
 * @Create 2025/9/25 23:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/file")
@Slf4j
public class FileController {

    @Autowired
    private OSSUtils ossUtils;

    @PostMapping("/upload")
    public String upload(MultipartFile file) throws IOException {
        //真实的文件名称
        String originalFilename = file.getOriginalFilename();
        //判断是否有文件
        if (StrUtil.isBlank(originalFilename)) {
            return "文件名称为空";
        }
        return ossUtils.upload(originalFilename, file.getBytes());
    }

    @DeleteMapping("/delete")
    public String delete(String url) {
        return ossUtils.delete(url);
    }
}
